/**
 * Created by IntelliJ IDEA.
 * User: mstine
 * Date: Mar 18, 2008
 * Time: 11:31:03 PM
 * To change this template use File | Settings | File Templates.
 */

//Discovering the Class
def s = "Hello"
println "s.class => ${s.class} \n"

//Constructors
println "Constructors:"
String.constructors.each{println it}
println()

//Interfaces
println "Interfaces:"
String.interfaces.each{println it}
println()

//Discovering the Fields of a Class
def d = new Date()
println "Date Fields:"
d.properties.each{println it}
println()

//Let's look at the MetaClass field
class Person {
    String firstname
    String lastname
}

def p = new Person(firstname:"John", lastname:"Smith")
p.properties.each{println it}

//How about for a Java Class?
println "Date.metaClass = ${Date.metaClass}\n"

//Checking for the existence of a Field
p = new Person()
if (p.metaClass.hasProperty(p, "firstname")) {
    p.firstname = "Jane"
}
println p.firstname

p.last = "Doe"

//GOTO: moreMetaprogramming.groovy